package com.cy.store.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author: AngJie
 * @create: 2022-02-11 15:02
 **/
//将当前类的对象的创建交给spring容器维护
@Component
//将当前类标记为切面类
@Aspect
public class TimeAspect {

    //ProceedingJoinPoint连接点 目标方法
    @Around("execution(* com.cy.store.service.impl.*.*(..))")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        //先记录当前时间
        long start = System.currentTimeMillis();
        Object result = proceedingJoinPoint.proceed();//调用目标方法
        //后调用当前时间
        long end = System.currentTimeMillis();

        System.out.println("耗时:" + (end - start));
        return result;
    }
}
